import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'

export default createStore({
  state: {
    isGetterRouter: false,
    isCollapse: false,
    userInfo: {},
    roleMenuList: []
  },
  getters: {},
  mutations: {
    changeMenuList(state, value) {
      // 控制路由的显示与隐藏
      state.roleMenuList = value
    },
    changeGetterRouter(state, value) {
      state.isGetterRouter = value
    },
    // 控制侧边栏展开
    changeCollapse(state) {
      state.isCollapse = !state.isCollapse
    },
    changeUserInfo(state, value) {
      state.userInfo = {
        ...state.userInfo,
        ...value
      }
    },
    clearUserInfo(state, value){
      state.userInfo = {}
    }
  },
  actions: {},
  modules: {},
  plugins: [createPersistedState({
    paths: ['isCollapse', 'userInfo', 'roleMenuList'] // 控制是否持久化
  })]
})
